<template>
  <!-- 员工实名认证审核 -->
  <div>
    <el-container>
      <!-- 网页头部 -->
      <el-header class="Header">
        <!-- 日期选择器 -->
        <el-date-picker
          v-model="selectDate"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          style="width: 500px"
        />
        <!-- 状态下拉框 -->
        <el-select v-model="userStates" clearable placeholder="请选择状态">
          <el-option label="通过" value="通过" />
          <el-option label="不通过" value="不通过" />
          <el-option label="未审核" value="未审核" />
        </el-select>
        <!-- 申请人编号输入框 -->
        <el-input
          v-model="userId"
          placeholder="申请人编号"
          style="width: 280px"
          clearable
        />
        <!-- 查询按钮 -->
        <el-button type="primary" @click="selectUser">查询</el-button>
      </el-header>
      <!-- 网页内容 -->
      <el-main class="Contents">
        <el-table :data="userData" style="width: 100%">
          <!-- 序号 -->
          <el-table-column type="index" label="序号" align="center" />
          <!-- 申请人编号 -->
          <el-table-column prop="userId" label="申请人编号" align="center" />
          <!-- 姓名 -->
          <el-table-column prop="realname" label="姓名" align="center" />
          <!-- 申请时间 -->
          <el-table-column
            prop="applyTime"
            label="申请时间"
            align="center"
            width="160px"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.applyTime | fmtDate_global }}</span>
            </template>
          </el-table-column>
          <!-- 身份证号 -->
          <el-table-column
            prop="idCard"
            label="身份证号"
            align="center"
            width="170px"
          />
          <!-- 身份证正面 -->
          <el-table-column
            prop="idcardPhotoPositive"
            label="身份证正面"
            align="center"
          >
            <template slot-scope="scope">
              <el-image
                style="width: 40px; height: 30px"
                :src="scope.row.idcardPhotoPositive"
                :preview-src-list="[scope.row.idcardPhotoPositive]"
              />
            </template>
          </el-table-column>
          <!-- 身份证反面 -->
          <el-table-column
            prop="idcardPhotoNegative"
            label="身份证反面"
            align="center"
          >
            <template slot-scope="scope">
              <el-image
                style="width: 40px; height: 30px"
                :src="scope.row.idcardPhotoNegative"
                :preview-src-list="[scope.row.idcardPhotoNegative]"
              />
            </template>
          </el-table-column>
          <!-- 银行卡号 -->
          <el-table-column
            prop="bankCard"
            label="银行卡号"
            align="center"
            width="180px"
          />
          <!-- 银行卡 -->
          <el-table-column prop="bankCardPhoto" label="银行卡" align="center">
            <template slot-scope="scope">
              <el-image
                style="width: 40px; height: 30px"
                :src="scope.row.bankCardPhoto"
                :preview-src-list="[scope.row.bankCardPhoto]"
              />
            </template>
          </el-table-column>
          <!-- 状态 -->
          <el-table-column label="状态" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == '通过'" type="success">通过</el-tag>
              <el-tag v-if="scope.row.status == '未审核'" type="info">未审核</el-tag>
              <el-tag v-if="scope.row.status == '不通过'" type="danger">未通过</el-tag>
            </template>
          </el-table-column>
          <!-- 操作 -->
          <el-table-column label="操作" align="center">
            <template v-if="scope.row.status == '未审核'" slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="passClick(scope.row.id)"
              >
                通过
              </el-button>
              <el-button
                type="text"
                size="small"
                style="color: red"
                @click="noPassClick(scope.row.id)"
              >
                不通过
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <!-- 分页底部 -->
      <el-footer class="Footer">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[2, 4, 6, 8]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-footer>
    </el-container>
  </div>
</template>

<script>
import { get } from '@/utils/request'
export default {
  data() {
    return {
      // 选择的时间-日期选择器
      selectDate: null,
      // 用户审核状态-下拉框
      userStates: '',
      // 申请人编号-输入框
      userId: null,
      // 分页 页面大小 当前页面
      pageSize: 8,
      currentPage: 1,
      total: 50,
      // 定义一个查询按钮获取到的对象
      queryData: {},
      // 表格内容数据
      userData: [],
      // 日期选择器显示时间
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              let end = new Date()
              let start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              let end = new Date()
              let start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              let end = new Date()
              let start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  computed: {},
  created() {
    this.getUserData()
  },
  mounted() {},
  methods: {
    // 审核通过
    async passClick(id) {
      let res = await get('/certification/checkPass', { id })
      console.log(res)
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      this.getUserData()
    },
    // 审核不通过
    async noPassClick(id) {
      let res = await get('/certification/checkNoPass', { id })
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      this.getUserData()
    },
    // 获取员工信息
    async getUserData() {
      let data = {
        page: this.currentPage,
        pageSize: this.pageSize
      }
      let res = await get('/certification/pageQueryCertificationApply', {
        ...data,
        ...this.queryData
      })
      this.userData = res.data.list
      this.total = res.data.total
      console.log(this.userData)
    },
    // 分页获取页面大小
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getUserData()
    },
    // 分页获取当前页面
    handleCurrentChange(val) {
      this.currentPage = val
      this.getUserData()
    },
    // 查询按钮 查询用户信息
    selectUser() {
      let data = {
        status: this.userStates,
        userId: this.userId
      }
      if (!(this.selectDate == null)) {
        data.beginTime = this.getTimestamp(this.selectDate[0])
        data.endTime = this.getTimestamp(this.selectDate[1])
      }
      for (let key in data) {
        if (!data[key]) {
          delete data[key]
        }
      }
      this.queryData = data
      this.currentPage = 1
      this.getUserData()
      // console.log(data);
    },
    // 把时间日期转成时间戳 方法
    getTimestamp(time) {
      return new Date(time).getTime()
    }
  }
}
</script>
<style scoped>
.Footer {
  position: fixed;
  bottom: 5px;
  right: 20px;
}
</style>
